package com.snailvr.tv.network;


import com.snail.readyvr.di.module.ApplicationModule;
import com.snailvr.tv.Definition;
import com.snailvr.tv.network.service.ChannelInfoService;
import com.snailvr.tv.network.service.ChannelListService;
import com.snailvr.tv.network.service.JXListService;
import com.snailvr.tv.network.service.RoomInfoService;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2016/8/31.
 */
public class RetrofitFactory {
    private static ChannelListService mChannelListService;
    private static ChannelInfoService mChannelInfoService;
    private static RoomInfoService mRoomInfoService;
    private static JXListService mJxListService;

    public static synchronized ChannelListService getmChannelsService() {
        /*HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
        logging.setLevel(HttpLoggingInterceptor.Level.BODY);//正式发布时去掉*/

        OkHttpClient client = new OkHttpClient.Builder()
                .connectTimeout(20, TimeUnit.SECONDS)
                .readTimeout(20, TimeUnit.SECONDS)
                .retryOnConnectionFailure(true)
               // .addInterceptor(logging)//正式发布时去掉
                .build();
        if (mChannelListService == null) {
            Retrofit retrofit = new Retrofit.Builder()
                    .baseUrl(ApplicationModule.HOST)
                    .client(client)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
            mChannelListService = retrofit.create(ChannelListService.class);
        }
        return mChannelListService;
    }

    public static synchronized ChannelInfoService getmChannelInfoService() {
       /* HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
        logging.setLevel(HttpLoggingInterceptor.Level.BODY);//正式发布时去掉*/

        OkHttpClient client = new OkHttpClient.Builder()
                .connectTimeout(20, TimeUnit.SECONDS)
                .readTimeout(20, TimeUnit.SECONDS)
                .retryOnConnectionFailure(true)
                //.addInterceptor(logging)//正式发布时去掉
                .build();
        if (mChannelInfoService == null) {
            Retrofit retrofit = new Retrofit.Builder()
                    .baseUrl(ApplicationModule.HOST)
                    .client(client)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
            mChannelInfoService = retrofit.create(ChannelInfoService.class);
        }
        return mChannelInfoService;
    }

    public static synchronized RoomInfoService getmRoomInfoService() {
        /*HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
        logging.setLevel(HttpLoggingInterceptor.Level.BODY);//正式发布时去掉*/

        OkHttpClient client = new OkHttpClient.Builder()
                .connectTimeout(20, TimeUnit.SECONDS)
                .readTimeout(20, TimeUnit.SECONDS)
                .retryOnConnectionFailure(true)
               // .addInterceptor(logging)//正式发布时去掉
                .build();
        if (mRoomInfoService == null) {
            Retrofit retrofit = new Retrofit.Builder()
                    .baseUrl(ApplicationModule.HOST)
                    .client(client)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
            mRoomInfoService = retrofit.create(RoomInfoService.class);
        }
        return mRoomInfoService;
    }

    public static synchronized JXListService getmJXListService() {
       /* HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
        logging.setLevel(HttpLoggingInterceptor.Level.BODY);//正式发布时去掉*/

        OkHttpClient client = new OkHttpClient.Builder()
                .connectTimeout(20, TimeUnit.SECONDS)
                .readTimeout(20, TimeUnit.SECONDS)
                .retryOnConnectionFailure(true)
                //.addInterceptor(logging)//正式发布时去掉
                .build();
        if (mJxListService == null) {
            Retrofit retrofit = new Retrofit.Builder()
                    .baseUrl(Definition.JX_HOST)
                    .client(client)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
            mJxListService = retrofit.create(JXListService.class);
        }
        return mJxListService;
    }
}


